package org.me.marble;

import android.os.Handler;
import android.graphics.Color;

/**
 *
 * @author tungi
 */

public class LoadingView implements Runnable{
    private int current_back=1;
    private GameActivity game;
    private boolean fired=false;

    public LoadingView(GameActivity game){
        this.game=game;
    }

    public void show(){   
        if(OptionsLibrary.sound)
        	SoundManager.playSound(sounds.Loading.ordinal(),0,1.0f);
        
        game.setContentView(R.layout.loadingview);
        
        int pic_id=GameActivity.game.getResources().
                getIdentifier("loading_background"+Integer.toString(current_back),
                "drawable", GameActivity.game.getPackageName());
        if(pic_id==0){
            current_back=1;
            pic_id=GameActivity.game.getResources().
                getIdentifier("loading_background"+Integer.toString(current_back),
                "drawable",GameActivity.game.getPackageName());
        }
        game.getWindow().setBackgroundDrawable(
        		new BackgroundImage(game,pic_id,Color.BLACK,0.5,0.5).getCurrent());
        current_back++;

        new Handler().postDelayed(this, 3000);
    }

    public void run(){
        fired=true;
        if(game.isLevelInitialized())
            //game.setContentView(game.getGameView());
            game.getGameView().setContentView();
    }

    public boolean isFired(){
        return fired;
    }

    public void deleteFireState(){
        fired=false;
    }
}
